//
//  CG.swift
//  
//
//  Created by bo wang on 2020/8/25.
//  Copyright © 2020 wangbo. All rights reserved.
//

import Foundation
import UIKit
import CoreGraphics

extension CGRect {
    var topLeft: CGPoint { CGPoint(x: minX, y: minY) }
    var topRight: CGPoint { CGPoint(x: maxX, y: minY) }
    var bottomLeft: CGPoint { CGPoint(x: minX, y: maxY) }
    var bottomRight: CGPoint { CGPoint(x: maxX, y: maxY) }
    var topMid: CGPoint { CGPoint(x: midX, y: minY) }
    var leftMid: CGPoint { CGPoint(x: minX, y: midY) }
    var bottomMid: CGPoint { CGPoint(x: midX, y: maxY) }
    var rightMid: CGPoint { CGPoint(x: maxX, y: midY) }
    var center: CGPoint { CGPoint(x: midX, y: midY) }
    
    init(_ x: CGFloat, _ y: CGFloat, _ w: CGFloat, _ h: CGFloat) {
        self.init(x: x, y: y, width: w, height: h)
    }
    
    init(_ x: Double, _ y: Double, _ w: Double, _ h: Double) {
        self.init(x: x, y: y, width: w, height: h)
    }
    
    init(_ x: Float, _ y: Float, _ w: Float, _ h: Float) {
        self.init(x: CGFloat(x), y: CGFloat(y), width: CGFloat(w), height: CGFloat(h))
    }
    
    init(_ x: Int, _ y: Int, _ w: Int, _ h: Int) {
        self.init(x: x, y: y, width: w, height: h)
    }
    
    init(_ size: CGSize) {
        self.init(origin: .zero, size: size)
    }
}

extension CGPoint {
    init(_ x: CGFloat, _ y: CGFloat) {
        self.init(x: x, y: y)
    }
    
    init(_ x: Double, _ y: Double) {
        self.init(x: x, y: y)
    }
    
    init(_ x: Float, _ y: Float) {
        self.init(x: CGFloat(x), y: CGFloat(y))
    }
    
    init(_ x: Int, _ y: Int) {
        self.init(x: x, y: y)
    }
}

extension CGSize {
    init(_ w: CGFloat, _ h: CGFloat) {
        self.init(width: w, height: h)
    }
    
    init(_ w: Double, _ h: Double) {
        self.init(width: w, height: h)
    }
    
    init(_ w: Float, _ h: Float) {
        self.init(width: CGFloat(w), height: CGFloat(h))
    }
    
    init(_ w: Int, _ h: Int) {
        self.init(width: w, height: h)
    }
}
